package com.ruyuan.eshop.order.service.impl;

import com.ruyuan.eshop.common.enums.OrderOperateTypeEnum;
import com.ruyuan.eshop.common.enums.OrderStatusChangeEnum;
import com.ruyuan.eshop.order.domain.entity.OrderInfoDO;
import com.ruyuan.eshop.order.domain.entity.OrderOperateLogDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author lxg
 * @Description:订单操作日志工厂
 * @date 2022/4/622:50
 */
@Component
@Slf4j
public class OrderOperateLogFactory {

    public OrderOperateLogDO get(OrderInfoDO order, OrderStatusChangeEnum orderStatusChangeEnum){
        OrderOperateTypeEnum orderOperateTypeEnum=orderStatusChangeEnum.getOperateType();
        int preStatus=orderStatusChangeEnum.getPreStatus().getCode();
        int currentStatus=orderStatusChangeEnum.getCurrentStatus().getCode();
        return create(order, orderOperateTypeEnum, preStatus, currentStatus, orderOperateTypeEnum.getMsg());

    }

    /**
     * 创建订单日志
     * @param order
     * @param orderType
     * @param preStatus
     * @param currentStatus
     * @param remark
     * @return
     */
    private OrderOperateLogDO create(OrderInfoDO order, OrderOperateTypeEnum orderType,int preStatus,int currentStatus,String remark){
        OrderOperateLogDO log=new OrderOperateLogDO();
        log.setOrderId(order.getOrderId());
        log.setCurrentStatus(currentStatus);
        log.setPreStatus(preStatus);
        log.setOperateType(orderType.getCode());
        log.setRemark(remark);
       return log;
    }
}
